<?php

	class Admin
	{
		var $admin_id;
		var $admin_username;
		var $admin_password;
		
		
		public function getAdminId()
		{
			return $this->admin_id;
		}
		public function setAdminId($admin_id)
		{	
			$this->admin_id=$admin_id;
		}


		public function getAdminUsername()
		{
			return $this->admin_username;
		}
		public function setAdminUsername($admin_username)
		{
			$this->admin_username=$admin_username;
		}


		public function getAdminPassword()
		{
			return $this->admin_password;
		}
		public function setAdminPassword($admin_password)
		{
			$this->admin_password=$admin_password;
		}


		public function adminLogin($adminusername,$adminpassword)
		{
			$query = mysql_query('SELECT * FROM admin WHERE 
			admin_username = "'.$adminusername.'" AND 
			admin_password = "'.$adminpassword.'" ')or die (mysql_error());

			$count = mysql_num_rows($query);
			if ($count!=0)
			{
				
				 $_SESSION['admin_id'] = session_id;
				 $_SESSION['admin_username'] = $adminusername;
				echo 'good';
			}
				echo "PASS";
		}
		public function adminLogout()
		{

		}


		public function adminAddSubject($subjectid,$subjectname,$subjectteacher,$subjectfaculty)
		{
			mysql_query('INSERT INTO subject (subject_id,subject_name,subject_teacher,subject_faculty) VALUES
			(
				"'.$subjectid.'","'.$subjectname.'","'.$subjectteacher.'","'.$subjectfaculty.'"
			)
			')or die(mysql_error());   
			return true;
		}
		public function adminDeleteSubject()
		{
			mysql_query('DELETE FROM subject WHERE sub_id = "'. $_POST['sub_id'] .'" LIMIT 1')or die (mysql_error()); 
		}
		public function adminEditSubject($sub_id,$subject_id,$subject_name,$subject_teacher,$subject_faculty)
		{
			mysql_query('UPDATE subject SET subject_id = "'. $_POST['subject_id'] .'" , subject_name = "'. $_POST['subject_name'] .'", subject_teacher = "'. $_POST['subject_teacher'] .'", subject_faculty = "'. $_POST['subject_faculty'] .'" WHERE sub_id="'. $_POST['sub_id'] .'" LIMIT 1')or die(mysql_error());
		}
		public function adminAddInformation($inf_title,$inf_date_start,$inf_date_end,$inf_subject,$inf_faculty,$inf_detail,$inf_type)
		{
			mysql_query('INSERT INTO main_information (inf_title,inf_date_start,inf_date_end,inf_subject,inf_faculty,inf_detail,inf_type) VALUES
			(
				"'.$inf_title.'","'.$inf_date_start.'","'.$inf_date_end.'","'.$inf_subject.'","'.$inf_faculty.'","'.$inf_detail.'","'.$inf_type.'"
			)
			')or die(mysql_error());   
			return true;
			
		}
		public function adminDeleteInformation()
		{
			mysql_query('DELETE FROM main_information WHERE inf_id = "'. $_POST['inf_id'] .'" LIMIT 1')or die (mysql_error()); 
		}
		public function adminEditInformation($inf_id,$inf_title,$inf_date_end,$inf_detail)
		{
			mysql_query('UPDATE main_information SET inf_title = "'. $inf_title .'" , inf_date_end = "'. $inf_date_end .'", inf_detail = "'. $inf_detail .'" WHERE inf_id="'. $inf_id .'" LIMIT 1')or die(mysql_error());
		}
		public function adminDeleteStudent()
		{
			mysql_query('DELETE FROM studentmember WHERE student_id = "'. $_POST['student_id'] .'" LIMIT 1')or die (mysql_error()); 
		}
		public function adminDeleteTeacher()
		{
			mysql_query('DELETE FROM teachermember WHERE teacher_id = "'. $_POST['teacher_id'] .'" LIMIT 1')or die (mysql_error()); 
		}
		public function adminShowScitech()
		{
			$query = mysql_query('SELECT * FROM main_information WHERE inf_faculty = "Sci-Tech"') or die(mysql_error()); 

			$data_array = array(); 

			while($arr = mysql_fetch_object($query)) 
				{


					$data_array[$arr->inf_id]['inf_id'] = $arr->inf_id; 
					$data_array[$arr->inf_id]['inf_title'] = $arr->inf_title; 
					$data_array[$arr->inf_id]['inf_subject'] = $arr->inf_subject; 
					$data_array[$arr->inf_id]['inf_date_start'] = $arr->inf_date_start;
					$data_array[$arr->inf_id]['inf_date_end'] = $arr->inf_date_end;
					$data_array[$arr->inf_id]['inf_detail'] = $arr->inf_detail;
					$data_array[$arr->inf_id]['inf_faculty'] = $arr->inf_faculty;
					$data_array[$arr->inf_id]['inf_type'] = $arr->inf_type;
					$data_array[$arr->inf_id]['inf_user'] = $arr->inf_user;
					
					
				} 
			echo json_encode($data_array); 
		}
		public function adminShowSubject()
		{
			$query = mysql_query('SELECT * FROM subject') or die(mysql_error()); 

			$data_array = array(); 

			while($arr = mysql_fetch_object($query)) 
				{
				
					$data_array[$arr->sub_id]['sub_id'] = $arr->sub_id; 
					$data_array[$arr->sub_id]['subject_id'] = $arr->subject_id; 
					$data_array[$arr->sub_id]['subject_name'] = $arr->subject_name; 
					$data_array[$arr->sub_id]['subject_teacher'] = $arr->subject_teacher;
					$data_array[$arr->sub_id]['subject_faculty'] = $arr->subject_faculty;
					
				} 
			echo json_encode($data_array); 
		}

		public function adminShowSubjectDetail()
		{
			$query = mysql_query('SELECT * FROM main_information WHERE inf_faculty = "'. $_GET['inf_subject'] .'"') or die(mysql_error()); 

			$data_array = array(); 

			while($arr = mysql_fetch_object($query)) 
				{
				
					$data_array[$arr->inf_id]['inf_id'] = $arr->inf_id; 
					$data_array[$arr->inf_id]['inf_title'] = $arr->inf_title; 
					$data_array[$arr->inf_id]['inf_subject'] = $arr->inf_subject; 
					$data_array[$arr->inf_id]['inf_date_start'] = $arr->inf_date_start;
					$data_array[$arr->inf_id]['inf_date_end'] = $arr->inf_date_end;
					$data_array[$arr->inf_id]['inf_detail'] = $arr->inf_detail;
					$data_array[$arr->inf_id]['inf_faculty'] = $arr->inf_faculty;
					$data_array[$arr->inf_id]['inf_type'] = $arr->inf_type;
					$data_array[$arr->inf_id]['inf_user'] = $arr->inf_user;
					
				} 
			echo json_encode($data_array); 
		}
		public function adminShowSeSubject()
		{
			$query = mysql_query('SELECT * FROM main_information WHERE inf_faculty = "Software"') or die(mysql_error()); 

			$data_array = array(); 

			while($arr = mysql_fetch_object($query)) 
				{


					$data_array[$arr->inf_id]['inf_id'] = $arr->inf_id; 
					$data_array[$arr->inf_id]['inf_title'] = $arr->inf_title; 
					$data_array[$arr->inf_id]['inf_subject'] = $arr->inf_subject; 
					$data_array[$arr->inf_id]['inf_date_start'] = $arr->inf_date_start;
					$data_array[$arr->inf_id]['inf_date_end'] = $arr->inf_date_end;
					$data_array[$arr->inf_id]['inf_detail'] = $arr->inf_detail;
					$data_array[$arr->inf_id]['inf_faculty'] = $arr->inf_faculty;
					$data_array[$arr->inf_id]['inf_type'] = $arr->inf_type;
					$data_array[$arr->inf_id]['inf_user'] = $arr->inf_user;
					
				} 
			echo json_encode($data_array); 
		}
		public function adminShowEcomSubject()
		{
			$query = mysql_query('SELECT * FROM main_information WHERE inf_faculty = "E-commerce"') or die(mysql_error()); 

			$data_array = array(); 

			while($arr = mysql_fetch_object($query)) 
				{


					$data_array[$arr->inf_id]['inf_id'] = $arr->inf_id; 
					$data_array[$arr->inf_id]['inf_title'] = $arr->inf_title; 
					$data_array[$arr->inf_id]['inf_subject'] = $arr->inf_subject; 
					$data_array[$arr->inf_id]['inf_date_start'] = $arr->inf_date_start;
					$data_array[$arr->inf_id]['inf_date_end'] = $arr->inf_date_end;
					$data_array[$arr->inf_id]['inf_detail'] = $arr->inf_detail;
					$data_array[$arr->inf_id]['inf_faculty'] = $arr->inf_faculty;
					$data_array[$arr->inf_id]['inf_type'] = $arr->inf_type;
					$data_array[$arr->inf_id]['inf_user'] = $arr->inf_user;
					
				} 
			echo json_encode($data_array); 
		}
		public function adminShowBcomSubject()
		{
			$query = mysql_query('SELECT * FROM main_information WHERE inf_faculty = "B-computer"') or die(mysql_error()); 

			$data_array = array(); 

			while($arr = mysql_fetch_object($query)) 
				{


					$data_array[$arr->inf_id]['inf_id'] = $arr->inf_id; 
					$data_array[$arr->inf_id]['inf_title'] = $arr->inf_title; 
					$data_array[$arr->inf_id]['inf_subject'] = $arr->inf_subject; 
					$data_array[$arr->inf_id]['inf_date_start'] = $arr->inf_date_start;
					$data_array[$arr->inf_id]['inf_date_end'] = $arr->inf_date_end;
					$data_array[$arr->inf_id]['inf_detail'] = $arr->inf_detail;
					$data_array[$arr->inf_id]['inf_faculty'] = $arr->inf_faculty;
					$data_array[$arr->inf_id]['inf_type'] = $arr->inf_type;
					$data_array[$arr->inf_id]['inf_user'] = $arr->inf_user;
					
				} 
			echo json_encode($data_array); 
		}
		public function adminShowItSubject()
		{
			$query = mysql_query('SELECT * FROM main_information WHERE inf_faculty = "IT"') or die(mysql_error()); 

			$data_array = array(); 

			while($arr = mysql_fetch_object($query)) 
				{


					$data_array[$arr->inf_id]['inf_id'] = $arr->inf_id; 
					$data_array[$arr->inf_id]['inf_title'] = $arr->inf_title; 
					$data_array[$arr->inf_id]['inf_subject'] = $arr->inf_subject; 
					$data_array[$arr->inf_id]['inf_date_start'] = $arr->inf_date_start;
					$data_array[$arr->inf_id]['inf_date_end'] = $arr->inf_date_end;
					$data_array[$arr->inf_id]['inf_detail'] = $arr->inf_detail;
					$data_array[$arr->inf_id]['inf_faculty'] = $arr->inf_faculty;
					$data_array[$arr->inf_id]['inf_type'] = $arr->inf_type;
					$data_array[$arr->inf_id]['inf_user'] = $arr->inf_user;
					
				} 
			echo json_encode($data_array); 
		}
		public function adminEditStudent($student_id,$student_firstname,$student_lastname,$student_ncuid,$student_email,$student_tel,$student_faculty)
		{
			mysql_query('UPDATE studentmember SET student_firstname = "'. $_POST['student_firstname'] .'" , student_lastname = "'. $_POST['student_lastname'] .'", student_lastname = "'. $_POST['student_lastname'] .'", student_ncuid = "'. $_POST['student_ncuid'] .'", student_email = "'. $_POST['student_email'] .'", student_tel = "'. $_POST['student_tel'] .'" WHERE student_id="'. $_POST['student_id'] .'" LIMIT 1')or die(mysql_error());
		}
		public function adminEditTeacher($teacher_firstname,$teacher_lastname,$teacher_ncuid,$teacher_email,$teacher_tel,$teacher_faculty)
		{
			mysql_query('UPDATE teachermember SET teacher_firstname = "'. $_POST['teacher_firstname'] .'" , teacher_lastname = "'. $_POST['teacher_lastname'] .'", teacher_lastname = "'. $_POST['teacher_lastname'] .'", teacher_ncuid = "'. $_POST['teacher_ncuid'] .'", teacher_email = "'. $_POST['teacher_email'] .'", teacher_tel = "'. $_POST['teacher_tel'] .'" WHERE teacher_id="'. $_POST['teacher_id'] .'" LIMIT 1')or die(mysql_error());
		}
		public function adminShowAllInformation()
		{
			$query = mysql_query('SELECT * FROM main_information') or die(mysql_error()); 

			$data_array = array(); 

			while($arr = mysql_fetch_object($query)) 
				{


					$data_array[$arr->inf_id]['inf_id'] = $arr->inf_id; 
					$data_array[$arr->inf_id]['inf_title'] = $arr->inf_title; 
					$data_array[$arr->inf_id]['inf_subject'] = $arr->inf_subject; 
					$data_array[$arr->inf_id]['inf_date_start'] = $arr->inf_date_start;
					$data_array[$arr->inf_id]['inf_date_end'] = $arr->inf_date_end;
					$data_array[$arr->inf_id]['inf_detail'] = $arr->inf_detail;
					$data_array[$arr->inf_id]['inf_faculty'] = $arr->inf_faculty;
					$data_array[$arr->inf_id]['inf_type'] = $arr->inf_type;
					
					
				} 
			echo json_encode($data_array); 
		}
		public function adminGetInformation()
		{
			$query = mysql_query('SELECT * FROM main_information WHERE inf_id = "'. $_GET['inf_id'] .'"') or die(mysql_error()); 
			$data_array = array(); 
			while($arr = mysql_fetch_object($query)) 
				{
					$data_array[$arr->inf_id]['inf_id'] = $arr->inf_id; 
					$data_array[$arr->inf_id]['inf_title'] = $arr->inf_title; 
					$data_array[$arr->inf_id]['inf_subject'] = $arr->inf_subject; 
					$data_array[$arr->inf_id]['inf_date_start'] = $arr->inf_date_start;
					$data_array[$arr->inf_id]['inf_date_end'] = $arr->inf_date_end;
					$data_array[$arr->inf_id]['inf_detail'] = $arr->inf_detail;
					$data_array[$arr->inf_id]['inf_faculty'] = $arr->inf_faculty;
					$data_array[$arr->inf_id]['inf_type'] = $arr->inf_type;
					$data_array[$arr->inf_id]['inf_user'] = $arr->inf_user;
				} 
			echo json_encode($data_array); 
		}		

		
	}
?>